import "package:flutter/material.dart";
import "package:myapp/_views/dynamic/type.dart";

class DynamicVideoWidget extends StatelessWidget {
  final DynamicVideoItem dynamicVideoItem;
  const DynamicVideoWidget({
    super.key,
    required this.dynamicVideoItem,
  });
  @override
  Widget build(BuildContext context) {
    String videoType = dynamicVideoItem.videoType;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Padding(
          padding:
              const EdgeInsets.only(bottom: 8, left: 12, right: 12, top: 8),
          child: AspectRatio(
            aspectRatio: 16 / 9,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(4),
              child: Stack(
                alignment: Alignment.bottomCenter,
                children: [
                  Container(
                    width: double.infinity,
                    height: double.infinity, //按比例设置高度
                    decoration: BoxDecoration(
                      color: Colors.black12,
                      image: DecorationImage(
                        image: AssetImage(dynamicVideoItem.coverUrl),
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
                  Container(
                    height: 36,
                    width: double.infinity,
                    decoration: const BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.bottomCenter,
                        end: Alignment.topCenter,
                        colors: [
                          Color.fromARGB(120, 0, 0, 0),
                          Color.fromARGB(80, 0, 0, 0),
                          Color.fromARGB(40, 0, 0, 0),
                          Color.fromARGB(0, 0, 0, 0),
                        ],
                      ),
                    ),
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: Padding(
                        padding: const EdgeInsets.only(left: 8),
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Container(
                              margin: const EdgeInsets.only(right: 10),
                              padding: const EdgeInsets.all(2),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(2),
                                color: const Color.fromARGB(85, 0, 0, 0),
                              ),
                              child: Text(
                                dynamicVideoItem.duration,
                                style: const TextStyle(
                                  color: Colors.white,
                                  fontSize: 12,
                                ),
                              ),
                            ),
                            Container(
                              margin: const EdgeInsets.only(right: 10),
                              child: Text(
                                '${dynamicVideoItem.viewCount == '' ? "-" : dynamicVideoItem.viewCount}观看',
                                style: const TextStyle(
                                  color: Colors.white,
                                  fontSize: 12,
                                ),
                              ),
                            ),
                            Container(
                              margin: const EdgeInsets.only(right: 10),
                              child: Text(
                                '${dynamicVideoItem.danmuCount == '' ? "-" : dynamicVideoItem.danmuCount}弹幕',
                                style: const TextStyle(
                                  color: Colors.white,
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                  videoType == 'playback' ||
                          videoType == 'dynamic' ||
                          videoType == 'animate'
                      ? Positioned(
                          top: 6,
                          right: 6,
                          child: VideoTypeTagWidget(
                            videoType: videoType,
                          ))
                      : const SizedBox.shrink()
                ],
              ),
            ),
          ),
        ),
        dynamicVideoItem.title != null
            ? Padding(
                padding: const EdgeInsets.only(bottom: 8, left: 8, right: 8),
                child: Text(
                  dynamicVideoItem.title ?? '',
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(
                    fontSize: 15,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              )
            : const SizedBox.shrink()
      ],
    );
  }
}

class VideoTypeTagWidget extends StatelessWidget {
  final String videoType;
  const VideoTypeTagWidget({
    super.key,
    required this.videoType,
  });
  @override
  Widget build(BuildContext context) {
    String text = '';
    bool isShowTag = true;
    switch (videoType) {
      case 'playback':
        text = '直播回放';
        break;
      case 'dynamic':
        text = '动态视频';
        break;
      case 'animate':
        text = '番剧';
      default:
        isShowTag = false;
        break;
    }
    return isShowTag
        ? Container(
            padding: const EdgeInsets.fromLTRB(4, 1, 4, 1),
            decoration: BoxDecoration(
              color: const Color.fromARGB(255, 255, 107, 156),
              borderRadius: BorderRadius.circular(2),
            ),
            child: Text(
              text,
              style: const TextStyle(
                color: Colors.white,
                fontSize: 10,
              ),
            ),
          )
        : const SizedBox.shrink();
  }
}
